<?php
@session_start();

include_once("../lib/functions.php");
getProjectRootPath();

$fileControlID="";
foreach($_FILES as $key=>$value)
{
	$fileControlID=$key;
}
if($fileControlID!="" && $_FILES[$fileControlID]!="")
{
	if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']!="")
	{
		$ext = explode('.', basename( $_FILES[$fileControlID]['name']));
		if(in_array(strtolower($ext[count($ext)-1]),array("jpg","jpeg","png","bmp","gif","vob","mp4","3gp","mp3","wav")))
		{
			$display_path = 'uploads/temp_post_media/'.$_SESSION['Allyfolio_User_ID'];
			$target_path="../".$display_path;
			if(!file_exists($target_path))
	        {
				mkdir($target_path,0777);
			}
			$fileName=$_FILES[$fileControlID]['name'];
			$Fullpath=$target_path ."/".$fileName;
			if(move_uploaded_file($_FILES[$fileControlID]['tmp_name'], $Fullpath)) 
			{
				if(in_array(strtolower($ext[count($ext)-1]),array("jpg","jpeg","png","bmp","gif")))
				{
					$mediaType="IMAGE";
				}
				else if(in_array(strtolower($ext[count($ext)-1]),array("vob","mp4","3gp")))
				{
					$mediaType="VIDEO";
				}
				else if(in_array(strtolower($ext[count($ext)-1]),array("mp3","wav")))
				{
					$mediaType="AUDIO";
				}
				echo "SUCCESS|~|".$display_path."/".$fileName."|~|".$mediaType;
			}
			else
			{
				echo "ERROR|~|Looks like there is some problem. Please try after some time.";
			}
		}
		else
		{
			echo "ERROR|~|Please Upload image and video only.";
		}
	}
}
?>